package cn.tedu.plus.datetime;

import java.util.Date;

public class DateDemo {
    public static void main(String[] args) {
        Date date1 = new Date();//现在时间
        System.out.println(date1);

        Date date2 = new Date(1000);//格林元年+毫秒
        System.out.println(date2);

        System.out.println();

        long time1 = date1.getTime(); //得到时间戳
        System.out.println(time1);
        long time2 = date2.getTime();
        System.out.println(time2);

        System.out.println();

        date1.setTime(time2);       //设置时间戳
        System.out.println(date1);
        date2.setTime(time1);
        System.out.println(date2);

        System.out.println();

        boolean result1 = date1.before(date2);
        System.out.println(result1);

        boolean result2 = date2.after(date1);
        System.out.println(result2);

        System.out.println();

        int year = date2.getYear() + 1900;
        System.out.println(year);

        int month = date2.getMonth() + 1;
        System.out.println(month);

        int date = date2.getDate();
        System.out.println(date);

        int week = date2.getDay();
        System.out.println(week);

        int hour = date2.getHours();
        System.out.println(hour);

        int minutes = date2.getMinutes();
        System.out.println(minutes);

        int seconds = date2.getSeconds();
        System.out.println(seconds);
    }
}
